﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Scala.Logic.Repositories;
using Scala.Logic;

namespace Scala.Data.Impl.Repo
{
    public class EventsRepo : BaseRepo<Event, int>, IEventRepo
    {
        public EventsRepo(ISessionProvider provider) : base(provider) { }

        #region IEventRepo Members

        public IEnumerable<Event> GetMounthedRecordsBydate(DateTime date)
        {            
            var founded = FindRange(x => x.FromDate.Year == date.Year && x.FromDate.Month == date.Month);
            return founded;
        }

        public IEnumerable<Event> GetNexts(int count)
        {
            return FindRange(x => x.FromDate >= DateTime.Now).OrderBy(x => x.FromDate).Take(count);
        }

        #endregion

        #region IEventRepo Members


        public IEnumerable<Event> GetNextsWithAType(EventType type)
        {
            return FindRange(x => x.FromDate >= DateTime.Now && x.EventType.Equals(type)).OrderBy(x => x.FromDate);
        }

        #endregion

        #region IEventRepo Members


        public int CountOfCrossDateEvents(DateTime starts, DateTime ends, EventType type)
        {
            return FindRange(x => x.EventType == type
                && x.FromDate >= starts && x.TillDate <= ends).Count();
        }

        #endregion
    }
}
